﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Xml;
using System.IO;
using HtmlAgilityPack;
using Newtonsoft;
using System.Text;
using System.Net;
/// <summary>
/// Summary description for ExchangeVietComBank
/// </summary>
/// 
namespace WorldExchange
{
    public class ExchangeVietComBank : Exchange
    {
        public ExchangeVietComBank()
        {
            this.LinkService = ConfigurationSettings.AppSettings["Vietcombank"].ToString();
        }
        public ExchangeVietComBank(string pUrl)
        {
            this.LinkService = pUrl;
        }
        #region "Method"
        public override void getExchange()
        {
           Boolean ret = true;
           
                # region "Gán Giá trị"
                Price a = new Price();
                a.Ma = "";
                a.Mua_CK = "";
                a.Mua_TM = "";
                a.Ban = "";
                AUD = a;
                CAD = a;
                CHF = a;
                DKK = a;
                EUR = a;
                GBP = a;
                HKD = a;
                INR = a;
                JPY = a;
                KRW = a;
                KWD = a;
                MYR = a;
                NOK = a;
                SEK = a;
                SGD = a;
                THB = a;
                USD = a;
                #endregion
                XmlDocument xmldoc = new XmlDocument();
                try
                {
                    //VNS.Web.HttpWeb webGet = new VNS.Web.HttpWeb();
                    string strXML = WebTool.getWebContent(this.LinkService);
                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(strXML);
                    HtmlNode node = doc.GetElementbyId("ctl00_Content_ExrateView");

                    HtmlNodeCollection listnode = node.SelectNodes("//tr");

                    # region "Gán Giá trị"
                    Price TempAUD = new Price();
                    TempAUD.Ma = listnode[1].ChildNodes[1].InnerText.Trim().ToString();
                    TempAUD.Mua_CK = listnode[1].ChildNodes[4].InnerText.Trim().ToString();
                    TempAUD.Mua_TM = listnode[1].ChildNodes[3].InnerText.Trim().ToString();
                    TempAUD.Ban = listnode[1].ChildNodes[5].InnerText.Trim().ToString();
                    AUD = TempAUD;

                    Price TempCAD = new Price();
                    TempCAD.Ma = listnode[2].ChildNodes[1].InnerText.Trim().ToString();
                    TempCAD.Mua_CK = listnode[2].ChildNodes[4].InnerText.Trim().ToString();
                    TempCAD.Mua_TM = listnode[2].ChildNodes[3].InnerText.Trim().ToString();
                    TempCAD.Ban = listnode[2].ChildNodes[5].InnerText.Trim().ToString();
                    CAD = TempCAD;

                    Price TempCHF = new Price();
                    TempCHF.Ma = listnode[3].ChildNodes[1].InnerText.Trim().ToString();
                    TempCHF.Mua_CK = listnode[3].ChildNodes[4].InnerText.Trim().ToString();
                    TempCHF.Mua_TM = listnode[3].ChildNodes[3].InnerText.Trim().ToString();
                    TempCHF.Ban = listnode[3].ChildNodes[5].InnerText.Trim().ToString();
                    CHF = TempCHF;

                    Price TempDKK = new Price();
                    TempDKK.Ma = listnode[4].ChildNodes[1].InnerText.Trim().ToString();
                    TempDKK.Mua_CK = listnode[4].ChildNodes[4].InnerText.Trim().ToString();
                    TempDKK.Mua_TM = listnode[4].ChildNodes[3].InnerText.Trim().ToString();
                    TempDKK.Ban = listnode[4].ChildNodes[5].InnerText.Trim().ToString();
                    DKK = TempDKK;

                    Price TempEUR = new Price();
                    TempEUR.Ma = listnode[5].ChildNodes[1].InnerText.Trim().ToString();
                    TempEUR.Mua_CK = listnode[5].ChildNodes[4].InnerText.Trim().ToString();
                    TempEUR.Mua_TM = listnode[5].ChildNodes[3].InnerText.Trim().ToString();
                    TempEUR.Ban = listnode[5].ChildNodes[5].InnerText.Trim().ToString();
                    EUR = TempEUR;

                    Price TempGBP = new Price();
                    TempGBP.Ma = listnode[6].ChildNodes[1].InnerText.Trim().ToString();
                    TempGBP.Mua_CK = listnode[6].ChildNodes[4].InnerText.Trim().ToString();
                    TempGBP.Mua_TM = listnode[6].ChildNodes[3].InnerText.Trim().ToString();
                    TempGBP.Ban = listnode[6].ChildNodes[5].InnerText.Trim().ToString();
                    GBP = TempGBP;

                    Price TempHKD = new Price();
                    TempHKD.Ma = listnode[7].ChildNodes[1].InnerText.Trim().ToString();
                    TempHKD.Mua_CK = listnode[7].ChildNodes[4].InnerText.Trim().ToString();
                    TempHKD.Mua_TM = listnode[7].ChildNodes[3].InnerText.Trim().ToString();
                    TempHKD.Ban = listnode[7].ChildNodes[5].InnerText.Trim().ToString();
                    HKD = TempHKD;

                    Price TempINR = new Price();
                    TempINR.Ma = listnode[8].ChildNodes[1].InnerText.Trim().ToString();
                    TempINR.Mua_CK = listnode[8].ChildNodes[4].InnerText.Trim().ToString();
                    TempINR.Mua_TM = listnode[8].ChildNodes[3].InnerText.Trim().ToString();
                    TempINR.Ban = listnode[8].ChildNodes[5].InnerText.Trim().ToString();
                    INR = TempINR;

                    Price TempJPY = new Price();
                    TempJPY.Ma = listnode[9].ChildNodes[1].InnerText.Trim().ToString();
                    TempJPY.Mua_CK = listnode[9].ChildNodes[4].InnerText.Trim().ToString();
                    TempJPY.Mua_TM = listnode[9].ChildNodes[3].InnerText.Trim().ToString();
                    TempJPY.Ban = listnode[9].ChildNodes[5].InnerText.Trim().ToString();
                    JPY = TempJPY;

                    Price TempKRW = new Price();
                    TempKRW.Ma = listnode[10].ChildNodes[1].InnerText.Trim().ToString();
                    TempKRW.Mua_CK = listnode[10].ChildNodes[4].InnerText.Trim().ToString();
                    TempKRW.Mua_TM = listnode[10].ChildNodes[3].InnerText.Trim().ToString();
                    TempKRW.Ban = listnode[10].ChildNodes[5].InnerText.Trim().ToString();
                    KRW = TempKRW;

                    Price TempKWD = new Price();
                    TempKWD.Ma = listnode[11].ChildNodes[1].InnerText.Trim().ToString();
                    TempKWD.Mua_CK = listnode[11].ChildNodes[4].InnerText.Trim().ToString();
                    TempKWD.Mua_TM = listnode[11].ChildNodes[3].InnerText.Trim().ToString();
                    TempKWD.Ban = listnode[11].ChildNodes[5].InnerText.Trim().ToString();
                    KWD = TempKWD;

                    Price TempMYR = new Price();
                    TempMYR.Ma = listnode[12].ChildNodes[1].InnerText.Trim().ToString();
                    TempMYR.Mua_CK = listnode[12].ChildNodes[4].InnerText.Trim().ToString();
                    TempMYR.Mua_TM = listnode[12].ChildNodes[3].InnerText.Trim().ToString();
                    TempMYR.Ban = listnode[12].ChildNodes[5].InnerText.Trim().ToString();
                    MYR = TempMYR;

                    Price TempNOK = new Price();
                    TempNOK.Ma = listnode[13].ChildNodes[1].InnerText.Trim().ToString();
                    TempNOK.Mua_CK = listnode[13].ChildNodes[4].InnerText.Trim().ToString();
                    TempNOK.Mua_TM = listnode[13].ChildNodes[3].InnerText.Trim().ToString();
                    TempNOK.Ban = listnode[13].ChildNodes[5].InnerText.Trim().ToString();
                    NOK = TempNOK;

                    Price TempSEK = new Price();
                    TempSEK.Ma = listnode[14].ChildNodes[1].InnerText.Trim().ToString();
                    TempSEK.Mua_CK = listnode[14].ChildNodes[4].InnerText.Trim().ToString();
                    TempSEK.Mua_TM = listnode[14].ChildNodes[3].InnerText.Trim().ToString();
                    TempSEK.Ban = listnode[14].ChildNodes[5].InnerText.Trim().ToString();
                    SEK = TempSEK;

                    Price TempSGD = new Price();
                    TempSGD.Ma = listnode[15].ChildNodes[1].InnerText.Trim().ToString();
                    TempSGD.Mua_CK = listnode[15].ChildNodes[4].InnerText.Trim().ToString();
                    TempSGD.Mua_TM = listnode[15].ChildNodes[3].InnerText.Trim().ToString();
                    TempSGD.Ban = listnode[15].ChildNodes[5].InnerText.Trim().ToString();
                    SGD = TempSGD;

                    Price TempTHB = new Price();
                    TempTHB.Ma = listnode[16].ChildNodes[1].InnerText.Trim().ToString();
                    TempTHB.Mua_CK = listnode[16].ChildNodes[4].InnerText.Trim().ToString();
                    TempTHB.Mua_TM = listnode[16].ChildNodes[3].InnerText.Trim().ToString();
                    TempTHB.Ban = listnode[16].ChildNodes[5].InnerText.Trim().ToString();
                    THB = TempTHB;

                    Price TempUSD = new Price();
                    TempUSD.Ma = listnode[17].ChildNodes[1].InnerText.Trim().ToString();
                    TempUSD.Mua_CK = listnode[17].ChildNodes[4].InnerText.Trim().ToString();
                    TempUSD.Mua_TM = listnode[17].ChildNodes[3].InnerText.Trim().ToString();
                    TempUSD.Ban = listnode[17].ChildNodes[5].InnerText.Trim().ToString();
                    USD = TempUSD;

                   
                   
                    #endregion

                   
                }
                catch (Exception ex)
                {
                    ret = false;
                    TLog.WriteErr("ExchangeVietComBank : getExchange", ex.ToString());
                }
            //set lai value moi cho du lieu
                if (ret)
                    this.setNewValue();
            //return ret;
        }
        #endregion
    }
}